from django import forms

"""重写form 父类init 方法，为表单添加样式"""


class BootStrapFrom(object):
    bootstrap_fields_exclude = []  # 不用下面样式的字段名

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            # name : 数据库的字段名
            if name in self.bootstrap_fields_exclude:
                continue
            old_class = field.widget.attrs.get('class', "")  # 获取原来标签所用的class属性
            field.widget.attrs['class'] = '%s form-control' % old_class
            field.widget.attrs['placeholder'] = '请输入%s' % field.label
